<?php include(dirname(__FILE__) . "/../functions.php"); ?>
<form id="ftpform" method="post" action="">

<ol class="graphicol">

<li><strong>Theme Directory Name</strong>: <input type="text" size="30"
                                                  id="ftp_theme_dirname" name="ftp_theme_dirname"
                                                  value="<?php
                                                  if ($thfr_css['ftp_theme_dirname'] == '') {
                                                    echo strtolower(str_replace(' ', '-', preg_replace("/[^a-zA-Z0-9\s]/", "", $thfr_css['themename'])));
                                                  } else {
                                                    echo $thfr_css['ftp_theme_dirname'];
                                                  } ?>"/> <span class="example">Example:</span><code>blue-theme-3</code><span
  style="padding-left: 20px; color: brown">No spaces or special
  characters.</span></li>

<li><span style="float: left; font-weight: bold">Choose files:</span> <input
  style="display: none" type="checkbox" id="ftpcheckall1"
  class="ftpcheckall" name="ftpcheckall1" checked="checked"> <label
  for="ftpcheckall1" class="checkuncheck" id="checkuncheckall">Check/Uncheck
  All</label> <br style="clear: both"/>

  <div class="submenu clearfix">
    <h3>Global files: <!--<span class="toggleupdown">&nbsp;</span>--></h3>
    <input style="display: none" type="checkbox" class="checkunchecksection-ftp" id="check-globalfiles" name="check-globalfiles" checked="checked"/>
    <label for="check-globalfiles" class="checkuncheck"></label>
  <span class="floatcheckbox">
    <input type="checkbox" id="lbstylecss" name="ftp_file_array[]" value="style.css" checked="checked"/>
    <label for="lbstylecss"><code>style.css</code></label>
  </span>
  <span class="floatcheckbox">
    <input type="checkbox" id="lbjavascript" name="ftp_file_array[]" value="javascript.js" checked="checked"/>
    <label for="lbjavascript"><code>javascript.js</code></label>
  </span>
  <span class="floatcheckbox">
    <input type="checkbox" id="lbfunctions" name="ftp_file_array[]" value="functions.php" checked="checked"/>
    <label for="lbfunctions"><code>functions.php</code></label>
  </span>
  <span class="floatcheckbox">
    <input type="checkbox" id="lbheader" name="ftp_file_array[]" value="header.php" checked="checked"/>
    <label for="lbheader"><code>header.php</code></label>
  </span>
  <span class="floatcheckbox">
    <input type="checkbox" id="lbfooter" name="ftp_file_array[]" value="footer.php" checked="checked"/>
    <label for="lbfooter"><code>footer.php</code></label>
  </span>
  <span class="floatcheckbox">
    <input type="checkbox" id="lbloop" name="ftp_file_array[]" value="loop.php" checked="checked"/>
    <label for="lbloop"><code>loop.php</code></label>
  </span>
  <span class="floatcheckbox">
    <input type="checkbox" id="lbcomments" name="ftp_file_array[]" value="comments.php" checked="checked"/>
    <label for="lbcomments"><code>comments.php</code></label>
  </span></div>

  <div class="submenu clearfix">
    <h3>Page Templates: <!--<span class="toggleupdown">&nbsp;</span>--></h3>
    <input style="display: none" type="checkbox" class="checkunchecksection-ftp" id="check-pagetemplates" name="check-pagetemplates" checked="checked"/>
    <label for="check-pagetemplates" class="checkuncheck"></label>
    <?php foreach ($thfr_css['pagetemplates'] as $pagetemplate) { ?>
    <span class="floatcheckbox"> <input type="checkbox" id="lb<?php echo $pagetemplate; ?>" name="ftp_file_array[]" value="<?php echo $pagetemplate; ?>.php" checked="checked"/>
	  <label for="lb<?php echo $pagetemplate; ?>"><code><?php echo $pagetemplate; ?>.php</code></label>
  </span>
    <?php } ?>
  </div>

  <?php
// Check which images are used in the CSS:
  $cssImagesArray = array();
  $available_selectors = tf_selectors();
  foreach ($available_selectors as $sel) {
    if (isset($thfr_css[$sel])) {
      if ($thfr_css[$sel]['background-image'] != '') {
        /*
        $cssImagesArray[] = preg_replace("/(.*)url\(\/uploads\/(.*?)\)(.*)/i", "\${2}",
                  $thfr_css[$sel]);
        */
        $cssImagesArray[] = str_replace("/uploads/", "", $thfr_css[$sel]['background-image']);
      }
    }
  }
  $cssImagesArray = array_unique($cssImagesArray);

// Beta 19: Check with images are used as foreground-images
  $foregroundImagesArray = array();
  if (isset($thfr_css['customdropimages'])) {
    foreach ($thfr_css['customdropimages'] as $name => $value) {
      $foregroundImagesArray[] = $value['file'];
    }
  }

  $files = scandir(THFRUPLOADPATH . '/');
  natcasesort($files);
  if (count($files) > 2) { /* The 2 accounts for . and .. */
    // All files
    $imgext = array('jpg', 'JPG', 'JPEG', 'jpeg', 'gif', 'GIF', 'png', 'PNG', 'bmp', 'BMP');
    foreach ($files as $file) {
      if (file_exists(THFRUPLOADPATH . '/' . $file)
        && $file != '.' && $file != '..' && in_array(file_extension($file), $imgext)
        && !is_dir(THFRUPLOADPATH . '/' . $file)
      ) {
        if (in_array($file, $cssImagesArray)) {
          $cssImages[] = $file;
        }
        else {
          $otherImages[] = $file;
        }
      }
    }

    ?><div class="submenu clearfix">
  <h3>Background Images:</h3><?php
    if (!empty($cssImages)) {
      ?>
      <!--<span class="toggleupdown">&nbsp;</span>--> <input
        style="display: none" type="checkbox" class="checkunchecksection-ftp"
        id="cssimagecheckall" name="cssimagecheckall" checked="checked"/> <label
        for="cssimagecheckall" class="checkuncheck"></label>
      <?php foreach ($cssImages as $image) { ?>
        <span class="floatcheckbox"> <input type="checkbox"
                                            id="images-<?php echo $image; ?>" name="ftp_file_array[]"
                                            value="images/<?php echo $image; ?>" checked="checked"/> <label
          for="images-<?php echo $image; ?>"><code><?php echo $image; ?></code></label>
  </span>
        <?php
      }
      echo "</div>";
    } else {
      echo "<em>- - none used in this theme - -</em></div>";
    }

    ?><div class="submenu clearfix">
  <h3>Foreground Images:</h3><?php
    if (!empty($foregroundImagesArray)) {
      ?>
      <!--<span class="toggleupdown">&nbsp;</span>--> <input
        style="display: none" type="checkbox" class="checkunchecksection-ftp"
        id="otherimagecheckall" name="otherimagecheckall" checked="checked"/>
      <label for="otherimagecheckall" class="checkuncheck"></label>
      <?php foreach ($foregroundImagesArray as $image) { ?>
        <span class="floatcheckbox"> <input type="checkbox"
                                            id="images-<?php echo $image; ?>" name="ftp_file_array[]"
                                            value="images/<?php echo $image; ?>" checked="checked"/> <label
          for="images-<?php echo $image; ?>"><code><?php echo $image; ?></code></label>
  </span>
        <?php
      }
      echo "</div>";
    } else {
      echo "<em>- - none used in this theme - -</em></div>";
    }
  } else {
    echo "You aren't using any custom images in the theme so there's nothing to choose here";
  }
  ?>


</li>
<li><strong>FTP host name:</strong> <input class="ftpinput" type="text"
                                           size="50" name="ftp_server_address"
                                           value="<?php echo $thfr_css['ftp_server_address']; ?>"/>
  &nbsp;&nbsp;(<a href="#ftphostnamemore">More info</a>) <br/>
  <strong>FTP user name:</strong> <input class="ftpinput" type="text"
                                         name="ftp_user_name" value="<?php echo $thfr_css['ftp_user_name']; ?>"/>

  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>FTP password:</strong> <input
    class="ftpinput" type="password" name="ftp_user_pass"
    value="<?php echo $thfr_css['ftp_user_pass']; ?>"/>
  <?php if (!$thfr_css['ftp_user_pass']) { ?>
    <em>Currently not saved (Re-type if empty)</em>
    <?php } ?>
  <br/>
  <strong>Path to WordPress "Themes" directory:</strong> <input
    class="ftpinput" type="text" size="70" name="ftp_remote_path"
    value="<?php echo $thfr_css['ftp_remote_path']; ?>"/> <br/>
  &nbsp;&nbsp;&nbsp;&nbsp;<span class="example">Example:</span>
  <code>public_html/yourdomainname.com/wp-content/themes/</code>
  &nbsp;&nbsp;(<a href="#wpthemedirmore">More info</a>)
</li>

<li>
  <table width="100%">
    <tr>
      <td style="vertical-align: top; padding-right: 30px">Test settings
        with <code>test1234.txt</code>:<br/>
        <br/>
        <a href="#" id="ftptestsubmit" class="downloadsubmit">Transfer <code>test1234.txt</code></a>
        <br/>

        <div id="ftptestsubmit-loading"><br/>
      <span style="color: red">Please wait... this can take 5 - 20
      seconds...</span><br/>
          <br/>
        </div>
        <div id="ftptestmessages"><br/>
        </div>

      </td>
      <td style="vertical-align: top; padding-right: 30px">&larr; test
        &nbsp;&nbsp;&nbsp;&nbsp;OR&nbsp;&nbsp;&nbsp;&nbsp; transfer &rarr;</td>
      <td style="vertical-align: top">Transfer the selected files now:<br/>
        <br/>
        <a href="#" id="ftpsubmit" class="downloadsubmit"><strong>TRANSFER
          FILES NOW</strong></a> <br/>

        <div id="ftpsubmit-loading"><br/>
      <span style="color: red">Please wait... this can take 10 - 30
      seconds...</span><br/>
          <br/>
        </div>
        <div id="ftpmessages"><br/>
        </div>

      </td>
    </tr>
  </table>
</li>

<li>Check the transfer logs above (displayed shortly after you clicked
  a button). Are there red error messages?<br/>
  <br/>
  If you are using this FTP function for the first time, <strong>do a
    test transfer</strong> first and then check if the test file <code>test1234.txt</code>
  was uploaded to the proper directory on your hosting account. You could
  do this with a FTP software (i.e. <a
    href="http://filezilla-project.org/" target="_blank">FileZilla</a>) or
  with the file manager of your hosting control panel.<br/>
  <br/>
</li>

</ol>


<h3>About the FTP Settings:</h3>
If you do not have this info, look into your web hosting control panel.
The info may be there, or you may be able to create a FTP account and
set this info yourself. Or, google for "[name-of-your-hosting-provider]
ftp settings" or similar. Or, ask your web hosting provider. <br/>
<br/>

<strong id="ftphostnamemore">"FTP host name" examples:</strong> (or:
"FTP server address", etc...)
<ul>
  <li>A subdomain of your domain: <code>ftp.mydomain.com</code></li>
  <li>Your domain with www: <code>www.mydomain.com</code></li>
  <li>Your domain without www: <code>mydomain.com</code></li>
  <li>A global FTP host name of your provider, for all customers: <code>ftp.your-provider.com</code></li>
  <li>An IP address would work, too: <code>237.128.103.56</code> (don't
    use this one, this is just an example)
  </li>
  <li>Do <strong>not</strong> include <code>http://</code> anywhere.</li>
</ul>
FTP host names at popular providers:
<ul>
  <li><strong>hostgator.com:</strong> ftp.yourdomain.com</li>
  <li><strong>bluehost.com:</strong> ftp.yourdomain.com</li>
  <li><strong>dreamhost.com:</strong> yourdomain.com</li>
  <li><strong>godaddy.com:</strong> yourdomain.com</li>
</ul>
<strong id="wpthemedirmore">"Path to WordPress Themes directory"</strong>:
<ul>
  <li>The relative path from your FTP home directory to the WordPress
    "Themes" (/wp-content/themes/) directory
  </li>
  <li>Usually starts with with <code>public_html/</code>, on some web
    servers it is <code>www/</code> instead.
  </li>
  <li>Example: <code>public_html/yourdomain.com/wp-content/themes/</code>
    or <code>www/yourdomain.com/wp-content/themes/</code></li>
  <li>Should end on <code>.../yourdomain.com/wp-content/themes/</code, or, if your WordPress installation is in a
    subdirectory such as "blog": <code>.../yourdomain.com/<strong>blog/</strong>wp-content/themes/</code></li>

</ul>
"Path to WP Themes directory" at popular providers:
<ul>
  <li><strong>hostgator.com:</strong> both work: <code>public_html/yourdomain.com/wp-content/themes/</code>
    and <code>www/yourdomain.com/wp-content/themes/</code></li>
  <li><strong>bluehost.com:</strong> like hostgator</li>
  <li><strong>dreamhost.com:</strong> has a custom control panel where
    you can set how domains are mapped to folders. Usually no public_html.
    Could be <code>home/username/yourdomain.com/wp-content/themes/</code>
    or different.
  </li>
  <li><strong>godaddy.com:</strong> depends on type of control panel
    used. See <a href="http://help.godaddy.com/article/1360">http://help.godaddy.com/article/1360</a>.
    Leave out the opening slash / from the examples on that help article
    page. For instance, if you use CPanel, use <code>home/username/public_html/yourdomain.com/wp-content/themes/</code>
  </li>
</ul>
</form>
